<?php
namespace app\common\loglic;

use app\common\loglic\Model;

class Detail extends Model
{
    //自增更新
    public function incUpdate($pkId=0, $field='detail_view', $num=1, $time=0)
    {
        if(!$pkId){
            return 0;
        }
        return db('detail')->where('detail_id',$pkId)->setInc($field, abs($num), $time);
    }

    //自减
    public function decUpdate($pkId=0, $field='detail_view', $num=1, $time=0)
    {
        if(!$pkId){
            return 0;
        }
        return db('detail')->where('detail_id',$pkId)->setDec($field, abs($num), $time);
    }

    //更新字段值
    public function fieldUpdate($ids=[], $field='detail_status', $value='normal')
    {
        if(!$ids || !$value){
            return false;
        }
        return db('detail')->where('detail_id','in',$ids)->setField($field, $value);
    }

    //按主键ID删除
    public function deleteId($pkId=0)
    {
        if(!$pkId){
            return 0;
        }
        return $this->modelDelete('common/Detail', ['detail_id'=>$pkId], 'typeMap,tagMap,logs');
    }

    //按主键ID查询
    public function getId($pkId=0, $cache=false, $field='*')
    {
        return $this->dbGet('detail', [
            'field' => $field,
            'cache' => $cache,
            'where' => [
                ['detail_id','eq',$pkId],
                ['detail_status','eq','normal'],
            ]
        ]);
    }
}